<?php


namespace App\Models\CacheModel;


use App\Models\Api\BaseCache;
use think\Log;
use AstroTool\Cache\CacheManage;

class ZlcrAstrAccountRecord extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.zlcr_astr_account_record';

    protected $cacheModel = 'astr_admin.astr_account_record';

    /**
     * 新增流水
     * @param int $astrId
     * @param array $recordData
     * @return bool
     */
    public function addRecord(int $astrId, array $recordData)
    {
        try
        {
            $data = [
                'astr_id' => $astrId,
                'type' => $recordData['type'], // 流水类型 1收入 2提现
                'gid' => $recordData['gid'],
                'qid' => $recordData['qid'],
                'good_amount' => $recordData['good_amount'], // 商品实际支付金额
                'proportion' => $recordData['proportion'],  // 收益比例
                'amount' => $recordData['amount'],  // 占星师 实际收益
                'balance' => $recordData['balance'],    // 占星师收益后 余额
                'question_type' => $recordData['question_type'] ?? 1,
                'create_time' => $recordData['create_time'],
                'status' => 1,
                'team_id' => $recordData['team_id'] ?? 0,
            ];

            $this->save($data);

            CacheManage::getInstance()->setCacheConfig($this->cacheModel, $astrId)->rmCache('list');
        }
        catch (\Exception $e)
        {
            Log::write('占星师流水新增错误；占星师ID【' . $astrId . '】;新增信息:' . json_encode($recordData, JSON_UNESCAPED_UNICODE) . ';错误信息:' . $e->getMessage() . "；错误文件「{$e->getFile()}」错误行数「{$e->getLine()}」");
            return false;
        }
        return true;
    }
}
